<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
?>
<script>    
    var MasterTHStore = createStore(false, 'mMasterTHStore', ['id_th_ajaran','tahun_ajaran',{name:'aktif',type:'bool'}], '<?php echo base_url(); ?>' + 'tahunajaran/get_rows');
    var MasterTHDStore = createStore(false, 'mMasterTHDStore', ['id_th_ajaran','semester',{name:'aktif',type:'bool'}], '<?php echo base_url(); ?>' + 'tahunajaran/get_rows_detail');
    var entrythdstore = createStore(false, 'mentrythdstore', ['semester',{name:'aktif',type:'bool'}], '<?php echo base_url(); ?>' + 'tahunajaran/get_rows_detail');
    var semesterstore =createArrayStore([['I','Ganjil'],['II','Genap']]);
    
    Ext.define('Writer.EntryTHD', {
        extend: 'Ext.data.Model',
        fields: [{
                name: 'semester',
                type: 'string',
                useNull: false
            }, {name:'aktif',type:'bool'}]
    
    });
    function addrecord_entrythd(){
        var vGrid = Ext.getCmp('gridethd');
        //        console.log(Plant);
        var rowentryjurnal = new Writer.EntryTHD({
            semester: '',
            aktif: false            
        });
        var edit = vGrid.getPlugin();
        edit.cancelEdit();
        vGrid.getStore().insert(0, rowentryjurnal);
        edit.startEdit(0, 0);
    }
    
    Ext.define('FormMth', {
        extend          : 'Ext.form.Panel',
        alias           : 'widget.mthForm',
        id              : 'FormMth_id',
        requires        : [
            'Ext.form.Field'
        ],
        defaultType     : 'textfield',
        defaults        : {
            allowBlank: false,
            labelAlign: 'left',
            labelWidth: 100
        },
        monitorValid: true,
        url: '<?php echo base_url(); ?>' + 'tahunajaran/update_rows',
        buttonAlign     : 'center',
        padding         : 5,
        style           : 'background-color: #fff;',
        border          : false,
        initComponent   : function(){
            this.items = [
                {
                    xtype: 'fieldcontainer',
                    //                    fieldLabel: 'Tahun Ajaran',
                    labelStyle: 'font-weight:bold;padding:0;',
                    layout: 'hbox',
                    defaultType: 'textfield',

                    fieldDefaults: {
                        labelAlign: 'top'
                    },

                    items: [
                        {
                            //                            flex: 1,
                            name: 'id_th_ajaran',
                            //                            anchor:'90%',
                            id: 'mth_id_th_ajaran',
                            tooltip: 'Field tidak boleh kosong',
                            //                            afterLabelTextTpl: required_css,
                            fieldLabel: 'ID Tahun Ajaran',
                            //                            fieldStyle: 'text-transform:uppercase;',
                            maxLength:10,
                            emptyText:'Auto Generate',
                            allowBlank:true
                            ,width:100
                            //                            ,
                            //                            listeners: {
                            //                                change: function(field, newValue, oldValue) {
                            //                                    field.setValue(newValue.toUpperCase());
                            //                                }
                            //                            }

                        }
                        ,{
                            //                        flex: 2,
                            margins: '0 0 0 5',

                            name: 'tahun_ajaran',
                            //                            anchor:'90%',
                            id: 'mth_tahun_ajaran',
                            tooltip: 'Field tidak boleh kosong',
                            afterLabelTextTpl: required_css,
                            fieldLabel: 'Tahun Ajaran',
                            fieldStyle: 'text-transform:uppercase;',
                            maxLength:20,
                            allowBlank:false,
                            listeners: {
                                change: function(field, newValue, oldValue) {
                                    field.setValue(newValue.toUpperCase());
                                }
                            }
                            ,width:100
                            ,emptyText: 'xxxx/xxxx',
                            maskRe: /[\d\\/]/,
                            regex: /^\d{4}\/\d{4}$/,
                            regexText: 'Must be in the format xxxx/xxxx'
                            //                            ,value:'2014/2015'
                        } 
                        ,{
                            xtype: 'checkboxfield',
                            margins: '0 0 0 5',
                            name: 'mth_aktif',
                            id: 'mth_aktif',
                            fieldLabel: 'Aktif'
                        }
                    ]},
                {
                    xtype:'grid',
                    id:'gridethd',
                    height:200,
                    store: entrythdstore,
                    stripeRows: true,
                    //                        loadMask: true,
                    stateful:true,
                    stateId:'stateGridEthd',   
                    selModel:Ext.create('Ext.selection.RowModel',{
                        listeners:{
                            selectionchange: function( scope, selected, eOpts ){
                                Ext.getCmp('gridethd').down('#delete').setDisabled(selected.length === 0);
                            }
                        }
                    })
                    //                        selType: 'cellmodel',
                    ,plugins: [
                        Ext.create('Ext.grid.plugin.RowEditing', {
                            clicksToMoveEditor: 1,
                            autoCancel: false,
                            listeners: {
                                cancelEdit: function(rowEditing, context) {
                                    // Canceling editing of a locally added, unsaved record: remove it
                                        
                                        
                                        
                                        
                                    if (context.record.phantom) {
                                        var rp=context.record;
                                        if(rp.data.semester==""){
                                            Ext.getCmp('gridethd').getStore().remove(context.record);
                                        }
                                            
                                    }
                                }
                            }
                        })
                        //                            Ext.create('Ext.grid.plugin.CellEditing', {
                        //                                clicksToEdit: 1
                        //                            })
                    ],
                    columns:[
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            items: [{
                                    iconCls: 'icon-delete',
                                    tooltip: 'Delete Plant',
                                    scope: this,
                                    handler: function(){
                                        var vGrid=Ext.getCmp('gridethd');
                                        var selection = vGrid.getView().getSelectionModel().getSelection()[0];
                                        if (selection) {
                                            vGrid.getStore().remove(selection);
                                        }
                                    }
                                }]
                        },
                        {
                            text: 'Semester',
                            dataIndex: 'semester',
                            sortable: false,
                            align:'center',
                            //                                flex:1,
                            width: 100,
                            editor:{
                                xtype: 'combo',                                                            
                                tooltip: 'Field tidak boleh kosong',
                                afterLabelTextTpl: required_css,
                                //                                    fieldLabel: 'Jenis Biaya',                        
                                id: 'mth_semester',
                                mode:'local',
                                store: semesterstore,
                                valueField: 'mid',
                                displayField: 'mtext',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false,
                                //                                    anchor: '90%',
                                //                                    hiddenName: 'id_jenis',
                                emptyText: 'Semester'    ,
                                listeners: {
                                    select:function( combo, records, eOpts ){
                                        var sexists=false;
                                        var saktif=false;
                                        entrythdstore.each(function(node){
                                            if(node.data.semester==combo.getValue()){
                                                sexists=true;
                                            }
                                            if(node.data.aktif){
                                                saktif=true;
                                            }
                                        });
                                        if(sexists){
                                            set_message(2, 'Semester Sudah Terdaftar !');
                                            combo.setValue('');
                                        }
                                        //                                            if(saktif){
                                        //                                                set_message(2, 'Sudah Ada Status Yang Aktif!');
                                        //                                                combo.setValue('');
                                        //                                            }
                                            
                                    }
                                }
                                    
                            }
                        }
                        ,{
                            xtype:'checkcolumn',
                            text: 'Aktif',
                            dataIndex: 'aktif',
                            sortable: false,
                            disabled :true,
                            disabledCls:'opacity: 0;',
                            width: 80,
                            editor:{
                                xtype: 'checkboxfield',
                                id: 'mthd_aktif'
                                ,listeners: {
                                    change:function( mthis, newValue, oldValue, eOpts ){
                                        console.log(newValue);
                                        console.log(oldValue);
                                        var sexists=false;
                                        var saktif=false;
                                        if(newValue){
                                            entrythdstore.each(function(node){
                                                if(node.data.semester!=Ext.getCmp('mth_semester').getValue()){
                                                    if(node.data.aktif){
                                                        saktif=true;
                                                    }                                                    
                                                }                                                
                                            });
                                        }
                                            
                                        //                                            if(sexists){
                                        //                                                set_message(2, 'Semester Sudah Terdaftar !');
                                        //                                                combo.setValue('');
                                        //                                            }
                                        if(saktif){
                                            set_message(2, 'Sudah Ada Status Yang Aktif!');
                                            mthis.setValue(false);
                                        }
                                            
                                    }
                                }
                            }
                        }
                            
                    ]
                    ,tbar:[{
                            text: 'Add',
                            iconCls: 'icons-add',
                            handler: function(){
                                var vthajaran = Ext.getCmp('mth_tahun_ajaran').getValue();
                                if(vthajaran){
                                    addrecord_entrythd();
                                }else{
                                    set_message(2, 'Tahun Ajaran Belum Diisi !!!');
                                }
                                    
                            }
                        }
                        , '-', {
                            itemId: 'delete',
                            text: 'Delete',
                            iconCls: 'icon-delete',
                            disabled: true,
                            handler: function(){
                                var vGrid=Ext.getCmp('gridethd');
                                var selection = vGrid.getView().getSelectionModel().getSelection()[0];
                                if (selection) {
                                    vGrid.getStore().remove(selection);
                                }
                            }
                        }
                    ]
                }
              
                                  
            ];
            this.buttons = [
                {
                    text: 'Simpan',                    
                    itemId: 'simpan',
                    id:'btn_mth_simpan',
                    iconCls: 'save',
                    formBind: true,
                    scope: this,
                    handler: this.submit
                },
                {
                    text: 'Batal',
                    action: 'cancel',
                    itemId: 'batal',
                    iconCls: 'cancel',
                    handler: function(){
                        this.up('window').close();
                    }
                }
            ];
            this.callParent(arguments);
        },
        submit: function(){
            var parcmd=Ext.getCmp('btn_mth_simpan').getText();
            if(parcmd === 'Simpan'){
                parcmd='insert';
            }else if(parcmd === 'Edit'){
                parcmd='update';
            }
        
            var postdata=new Array();       
            var strethd=Ext.getCmp('gridethd').getStore();
            strethd.each(function(node){
                postdata.push(node.data);
            });
            Ext.getCmp('FormMth_id').getForm().submit({
                url: this.url,
                scope: this,
                //                success: this.onSuccess,
                //                failure: this.onFailure,
                params: {
                    cmd: parcmd   ,
                    postdata: Ext.JSON.encode(postdata)
                },
                waitMsg: 'Saving Data...',
                success: function(form, action) {
                    //                    console.log(action);
                    set_message(0,action.result.msg);
                    //                    Ext.Msg.alert('Success', action.result.msg);
                    Ext.getCmp('gridmth').store.reload(); 
                    //                    mth_id_th_ajaran
                    Ext.getCmp('gridthd').store.reload(); 
                    Ext.getCmp('gridethd').getStore().removeAll();
                    
                    Ext.getCmp('FormMth_id').getForm().reset();
                    Ext.getCmp('WindowMth_id').close();
                },
                failure: function(form, action) {
                    if(action.result.msg=='Session Expired') {
                        session_expired(action.result.msg);
                    }else{
                        set_message(1, action.result.msg);
                    }
                                            
                    
                }
            });
        } // eo function submit        
        ,
        showError: function(msg, title){
            title = title || 'Error';
            Ext.Msg.show({
                title: title,
                msg: msg,
                modal: true,
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                fn: function(btn){
                    if (btn == 'ok' && msg == 'Session Expired') {
                        window.location = '<?= site_url("auth/login") ?>';
                    }
                }
            });
        }
    });

    Ext.define('WindowMth', {
        extend          : 'Ext.window.Window',
        title           : 'Form Edit Tahun Ajaran',
        width           : 400,
        height          : 350,
        layout          : 'fit',
        autoShow        : true,
        modal           : true,
        alias           : 'widget.MthEdit',
        id              : 'WindowMth_id',
        initComponent   : function(){
            this.items = [
                Ext.widget('mthForm')
            ];
            this.callParent(arguments);
        }

    });
    Ext.define('MyTabSettingTahunAjaran', {
        extend: 'Ext.container.Container',
        xtype: 'TabSettingTahunAjaran',
        alias: 'widget.TabSettingTahunAjaran',
        title: 'Setting Tahun Ajaran',
        id: 'tab6',
        closable: true,        
        layout: 'border',
        items: [{
                xtype: 'panel',
                autoShow: true,
                id: 'panelth',            
                region: 'center',
                margins: '5 5 5 5',
                layout: 'border',
                
                items:[{
                        xtype:'grid',
                        region:'center',
                        id:'gridmth',
                        title:'Tahun Ajaran',
                        stateful:true,
                        stateId:'stateGridth',
                        store: MasterTHStore,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                        stripeRows: true,
                        loadMask: true,
                        //                        sm:sm_masteraccount,
                        columns:[
                            {
                                header: 'Edit/Delete',
                                menuDisabled: true,
                                sortable: false,
                                xtype: 'actioncolumn',
                                width: 70,
                                items: [
                                    {
                                        iconCls: 'icon-edit-record',
                                        tooltip: 'Edit Row',
                                        handler: function(grid, rowIndex, colIndex) {
                                            var rec = grid.getStore().getAt(rowIndex);
                                            var winmth=Ext.create('WindowMth');
                                            winmth.setTitle('Edit Form');
                                            Ext.getCmp('btn_mth_simpan').setText('Edit');
                                            Ext.getCmp('btn_mth_simpan').setIconCls('icon-edit-record');
                                            Ext.getCmp('mth_id_th_ajaran').setReadOnly(true);
                                            Ext.getCmp('mth_id_th_ajaran').setFieldStyle('readonly-input');
                                            Ext.getCmp('mth_id_th_ajaran').setValue(rec.get('id_th_ajaran'));
                                            Ext.getCmp('mth_tahun_ajaran').setValue(rec.get('tahun_ajaran')); 
                                            Ext.getCmp('mth_aktif').setValue(rec.get('aktif')); 
                                            var strg= Ext.getCmp('gridethd').getStore();
                                            strg.getProxy().setExtraParam("query",rec.get('id_th_ajaran'));
                                            strg.load();
                                            winmth.show();
                                        }
                                    },{
                                        getClass: function(v, meta, rec) {
                                            return 'icon-delete';
                                        },
                                        getTip: function(v, meta, rec) {
                                            return 'Delete Plant';
                                        },
                                        handler: function(grid, rowIndex, colIndex) {
                                            var rec = grid.getStore().getAt(rowIndex);
                                            console.log(rec.data);
                                            //                                            Ext.Msg.alert('Delete', 'Delete ' + rec.get('rekening'));
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Are you sure delete selected row ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                    
                                                        var data = '';
                                                        data = Ext.JSON.encode(rec.data);
                        
                                                        Ext.Ajax.request({                                                            
                                                            url: '<?php echo base_url(); ?>' +'tahunajaran/delete_row',
                                                            method: 'POST',
                                                            params: {
                                                                cmd: 'delete',
                                                                postdata: data
                                                            },
                                                            success: function(obj) {
                                                                var   resp = Ext.decode(obj.responseText);                                                                
                                                                if(resp.success==true){
                                                                    //                                                                    Ext.Msg.alert('info',resp.msg);
                                                                    set_message(0,resp.msg);
                                                                    Ext.getCmp('gridmth').store.reload();                                                                                                                                     
                                                                }else{
                                                                    Ext.Msg.show({
                                                                        title: 'Error',
                                                                        msg: resp.msg,
                                                                        modal: true,
                                                                        icon: Ext.Msg.ERROR,
                                                                        buttons: Ext.Msg.OK,
                                                                        fn: function(btn){
                                                                            if (btn == 'ok' && resp.msg == 'Session Expired') {
                                                                                window.location = '<?= site_url("auth/login") ?>';
                                                                            }
                                                                        }
                                                                    });
                                                                }
                                                            },
                                                            failure: function(obj) {
                                                                var  resp = Ext.decode(obj.responseText);
                                                                set_message(0, resp.reason);
                                                                //                                                                Ext.Msg.alert('info',resp.reason);
                                                            }                                                            
                                                        });                 
                                                    } 
                                                }
                                            });
                                        }
                                    }
                                ]
                            }
                           
                            ,
                            {
                                header: "ID Tahun Ajaran",
                                dataIndex: 'id_th_ajaran',
                                sortable: true,
                                width: 100
                            }
                            ,{
                                header: "Tahun Ajaran",
                                dataIndex: 'tahun_ajaran',
                                sortable: true,
                                width: 100
                            },{
                                xtype:'checkcolumn',
                                text: 'Aktif',
                                dataIndex: 'aktif',
                                sortable: false,
                                //                                disabled :true,
                                //                                disabledCls:'opacity: 0;',
                                width: 80
                                ,listeners:{
                                    checkchange:function( grid, rowIndex, checked, eOpts ){
                                        //                                       var rec = Ext.getCmp('userset_grid').getStore().getAt(rowIndex);
                                        if(checked){
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Apakah anda akan mengaktifkan tahun ajaran tersebut ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                                                        var rec = Ext.getCmp('gridmth').getStore().getAt(rowIndex);                                                                                                                
                                                        set_mth_update(rec.data,'setaktif','setaktif');
                                                    }else{
                                                        Ext.getCmp('gridmth').getStore().reload();
                                                    }
                                                    
                                                }
                                            });
                                        }else{
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Apakah anda TIDAK akan mengaktifkan tahun ajaran tersebut ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                                                        var rec = Ext.getCmp('gridmth').getStore().getAt(rowIndex);                                                                                                                
                                                        set_mth_update(rec.data,'setaktif','setaktif');
                                                    }else{
                                                        Ext.getCmp('gridmth').getStore().reload();
                                                    }
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        
                        ]
                        ,listeners:{
                            itemclick:function( scope, record, item, index, e, eOpts ){
                                console.log(record.data.id_th_ajaran);
                                var vid=record.data.id_th_ajaran;
                                var strg= Ext.getCmp('gridthd').getStore();
                                strg.getProxy().setExtraParam("query",vid);
                                strg.reload();
                                //                                    reload({params:{query:vid}});
                                Ext.getCmp('gridthd').expand();                                        
                            }
                        }
                        ,tbar:{
                            xtype: 'toolbar',
                            padding:'2 0 2 5',
                            items: [
                                {
                                    xtype: 'button',
                                    text: 'Add',
                                    iconCls: 'icons-add',
                                    onClick: function()
                                    {
                                        var winmth=Ext.create('WindowMth');
                                        winmth.setTitle('Add Form');
                                        Ext.getCmp('btn_mth_simpan').setText('Simpan');
                                        Ext.getCmp('btn_mth_simpan').setIconCls('icons-add');
                                        Ext.getCmp('mth_id_th_ajaran').setReadOnly(true);
                                        Ext.getCmp('mth_id_th_ajaran').setFieldStyle('readonly-input');
                                        //                                        setDefaultStoreProxy(KelompokAccountStore, urlKelompok);
                                        winmth.show();
                                    } 
                                },
                                '-',
                                {
                                    width: 300,
                                    //                                fieldLabel: 'Search',
                                    //                                labelWidth: 50,
                                    xtype: 'searchfield',
                                    store: MasterTHStore,
                                    emptyText: 'Quick Search...'
                                }
                            ]
                        }
                        ,bbar:{                        
                            xtype: 'pagingtoolbar',
                            store: MasterTHStore,pageSize: ENDPAGE,
                            displayInfo: true
                            //                    plugins: Ext.create('Ext.ux.SlidingPager', {})
                        }

                    },
                    {
                        xtype:'grid',
                        region:'east',
                        width: 500,
                        id:'gridthd',
                        title:'Tahun Ajaran Detail',
                        stateful:true,
                        stateId:'stateGridthd',
                        store: MasterTHDStore,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                        stripeRows: true,
                        loadMask: true,
                        split:true,
                        collapsible: true,
                        collapsed:true,
                        //                        sm:sm_masteraccount,
                        columns:[
                            {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            items: [{
                                    iconCls: 'icon-delete',
                                    tooltip: 'Delete Plant',
                                    scope: this,
                                    handler: function(grid, rowIndex, colIndex){
//                                        var vGrid=Ext.getCmp('gridthd').getStore();
                                        var rec = grid.getStore().getAt(rowIndex);
//                                            console.log(rec.data);
                                            //                                            Ext.Msg.alert('Delete', 'Delete ' + rec.get('rekening'));
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Are you sure delete selected row ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                    
                                                        var data = '';
                                                        data = Ext.JSON.encode(rec.data);
                        
                                                        Ext.Ajax.request({                                                            
                                                            url: '<?php echo base_url(); ?>' +'tahunajaran/delete_row_detail',
                                                            method: 'POST',
                                                            params: {
                                                                cmd: 'delete',
                                                                postdata: data
                                                            },
                                                            success: function(obj) {
                                                                var   resp = Ext.decode(obj.responseText);                                                                
                                                                if(resp.success==true){
                                                                    //                                                                    Ext.Msg.alert('info',resp.msg);
                                                                    set_message(0,resp.msg);
                                                                    Ext.getCmp('gridthd').store.reload();                                                                                                                                     
                                                                }else{
                                                                    Ext.Msg.show({
                                                                        title: 'Error',
                                                                        msg: resp.msg,
                                                                        modal: true,
                                                                        icon: Ext.Msg.ERROR,
                                                                        buttons: Ext.Msg.OK,
                                                                        fn: function(btn){
                                                                            if (btn == 'ok' && resp.msg == 'Session Expired') {
                                                                                window.location = '<?= site_url("auth/login") ?>';
                                                                            }
                                                                        }
                                                                    });
                                                                }
                                                            },
                                                            failure: function(obj) {
                                                                var  resp = Ext.decode(obj.responseText);
                                                                set_message(0, resp.reason);
                                                                //                                                                Ext.Msg.alert('info',resp.reason);
                                                            }                                                            
                                                        });                 
                                                    } 
                                                }
                                            });
                                        
                                    }
                                }]
                        },
                            {
                                header: "ID Tahun Ajaran",
                                dataIndex: 'id_th_ajaran',
                                sortable: true,
                                width: 100
                            }
                            ,{
                                header: "Semester",
                                dataIndex: 'semester',
                                sortable: true,
                                width: 100
                            }
                            ,{
                                xtype:'checkcolumn',
                                text: 'Aktif',
                                dataIndex: 'aktif',
                                sortable: false,
                                //                                disabled :true,
                                //                                disabledCls:'opacity: 0;',
                                width: 80
                                ,listeners:{
                                    checkchange:function( grid, rowIndex, checked, eOpts ){
                                        //                                       var rec = Ext.getCmp('userset_grid').getStore().getAt(rowIndex);
                                        if(checked){
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Apakah anda akan mengaktifkan semester tersebut ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                                                        var rec = Ext.getCmp('gridthd').getStore().getAt(rowIndex);                                                                                                                
                                                        set_thd_update(rec.data,'setaktif','setaktif_detail');
                                                    }else{
                                                        Ext.getCmp('gridthd').getStore().reload();
                                                    }
                                                    
                                                }
                                            });
                                        }else{
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Apakah anda TIDAK akan mengaktifkan semester tersebut ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                                                        var rec = Ext.getCmp('gridthd').getStore().getAt(rowIndex);                                                                                                                
                                                        set_thd_update(rec.data,'setaktif','setaktif_detail');
                                                    }else{
                                                        Ext.getCmp('gridthd').getStore().reload();
                                                    }
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        ],bbar:{                        
                            xtype: 'pagingtoolbar',
                            store: MasterTHDStore,pageSize: ENDPAGE,
                            displayInfo: true
                            //                    plugins: Ext.create('Ext.ux.SlidingPager', {})
                        }
                    }
                ]
            }
            //            ,{
            //                xtype: 'panel',
            //                autoShow: true,
            //                id: 'panelthd',            
            //                title:'Tahun Ajaran Detail',
            //                region: 'west',
            //                margins: '5 5 5 5',
            //                layout: 'fit',
            //                items:[
            //                ]
            //            }
        ],
        listeners:{
            show:function(){
                var storegrid=Ext.getCmp('gridmth').store;                
                storegrid.loadPage(1);                 
                
            }
        }
    });
    function set_mth_update(rec,cmd,vurl){
    
        var parcmd=cmd;
        var parUrl='<?php echo base_url(); ?>' +'tahunajaran/' + vurl;
        var data = '';
        data = Ext.JSON.encode(rec);
                                                                    
        Ext.Ajax.request({                                                            
            url: parUrl,
            method: 'POST',
            params: {
                cmd: parcmd,
                postdata: data
            },
            success: function(obj) {
                var   resp = Ext.decode(obj.responseText);                                                                
                if(resp.success==true){
                    set_message(0,resp.msg);
                    Ext.getCmp('gridmth').store.reload();
                                                                    
                }else{
                    Ext.Msg.show({
                        title: 'Error',
                        msg: resp.msg,
                        modal: true,
                        icon: Ext.Msg.ERROR,
                        buttons: Ext.Msg.OK,
                        fn: function(btn){
                            if (btn == 'ok' && resp.msg == 'Session Expired') {
                                window.location = '<?= site_url("auth/login") ?>';
                            }
                        }
                    });
                }
            },
            failure: function(obj) {
                var  resp = Ext.decode(obj.responseText);
                Ext.Msg.alert('info',resp.reason);
            }
        });     
        }
        
        function set_thd_update(rec,cmd,vurl){
    
        var parcmd=cmd;
        var parUrl='<?php echo base_url(); ?>' +'tahunajaran/' + vurl;
        var data = '';
        data = Ext.JSON.encode(rec);
                                                                    
        Ext.Ajax.request({                                                            
            url: parUrl,
            method: 'POST',
            params: {
                cmd: parcmd,
                postdata: data
            },
            success: function(obj) {
                var   resp = Ext.decode(obj.responseText);                                                                
                if(resp.success==true){
                    set_message(0,resp.msg);
                    Ext.getCmp('gridthd').store.reload();
                                                                    
                }else{
                    Ext.Msg.show({
                        title: 'Error',
                        msg: resp.msg,
                        modal: true,
                        icon: Ext.Msg.ERROR,
                        buttons: Ext.Msg.OK,
                        fn: function(btn){
                            if (btn == 'ok' && resp.msg == 'Session Expired') {
                                window.location = '<?= site_url("auth/login") ?>';
                            }
                        }
                    });
                }
            },
            failure: function(obj) {
                var  resp = Ext.decode(obj.responseText);
                Ext.Msg.alert('info',resp.reason);
                Ext.getCmp('gridthd').store.reload();
            }
        });     
        }
</script>
